const { CleanWebpackPlugin } = require("clean-webpack-plugin"); // clean插件
const CopyPlugin = require("copy-webpack-plugin");
const path = require("path");
const _externals = require("externals-dependencies");
module.exports = {
  mode: "none",
  entry: "./src/index.ts", // 指定入口文件
  output: {
    path: path.resolve(__dirname, "dist"), // 指定打包文件的目录
    filename: "bundle.js", // 打包后文件的名称
  },
  // 指定webpack打包时要使用的模块
  module: {
    // 指定loader加载的规则
    rules: [
      {
        test: /\.ts$/, // 指定规则生效的文件：以ts结尾的文件
        use: "ts-loader", // 要使用的loader
        exclude: /node-modules/, // 要排除的文件
      },
    ],
  },

  plugins: [
    new CleanWebpackPlugin(), // 自动清理dist目录
    new CopyPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, "./package.json"),
          to: path.resolve(__dirname, "./dist"),
        },
        {
          from: path.resolve(__dirname, "./Dockerfile"),
          to: path.resolve(__dirname, "./dist"),
        },
      ],
    }),
  ],

  // 设置哪些文件类型可以作为模块被引用
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
    extensions: [".ts", ".js"],
    fallback: {
      async_hooks: false,
    },
  },
  target: "node",
  externals: _externals(),
  context: __dirname,
};
